


import {
  get,
  post,
  put,
} from "./base_service"


/**
 * 佳宝礼品卡相关接口
 *
 * allen  2023-12-19
 */

/**
 * 
 * 礼品卡详情接口
 * 
 */
const queryGiftDetail = () => {
  return new Promise((resolve, reject) => {
    get("/api/front/collect/add").then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.message)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}

/**
 * 
 * 礼品卡列表
 * 
 */
const giftList = () => {
  return new Promise((resolve, reject) => {
    get("/api/front/gift/setting/list").then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.message)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}

/**
 * 
 * 礼品卡绑定接口
 * data:{
 *   cardNo:"",卡编号
 *   smsCode:"",//短信验证码
 * }
 */
const giftBind = (data) => {
  return new Promise((resolve, reject) => {
    post("/api/front/gift/oper/bind", data).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.message)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}


/**
 * 
 * 礼品卡购买接口
 * data:{
 *   cardId:"",
 * payType:"weixin",
 *   from:"routine"
 * }
 */
const buyCard = (data) => {
  return new Promise((resolve, reject) => {
    post("/api/front/gift/oper/buy", data).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.message)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}

/**
 * 
 * 礼品卡购买记录
 * data:{
 *    page:1,
 *    limit:10
 * }
 */
const buyCardRecord = (data) => {
  return new Promise((resolve, reject) => {
    get("/api/front/gift/user/list/buy", data).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.message)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}

/**
 * 
 * 礼品卡绑定记录
 * data:{
 *    page:1,
 *    limit:10
 * }
 */
const bindCardRecord = (data) => {
  return new Promise((resolve, reject) => {
    get("/api/front/gift/user/list/bind", data).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.message)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}

/**
 * 
 * 礼品卡消费记录
 * data:{
 *    page:1,
 *    limit:10
 * }
 */
const cardConsumeRecord = (page,limit) => {
  return new Promise((resolve, reject) => {
    get("/api/front/gift/user/list/use?page=" + page + "&limit=" + limit).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.message)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}

module.exports = {
  queryGiftDetail,
  giftBind,
  buyCard,
  buyCardRecord,
  bindCardRecord,
  cardConsumeRecord,//礼品卡消费记录
  giftList,//礼品卡列表
}

